//Author: Jair Cazarin <slipvayne@gmail.com>

#include<iostream>
#include<string>
#define MAX 250

using namespace std;

int m, n;
char image[MAX+1][MAX+1];



void I(int x1, int y1)
{
	m = x1;
	n = y1;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            image[i][j] = 'O';
    }
}

void C()
{
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            image[i][j] = 'O';
    }
}

void L(int x, int y, char c)
{
    image[y-1][x-1] = c;
}

void V(int x, int y1, int y2, char c)
{
    if(y2 > y1)
    {
        for(int i = y1 - 1; i <= y2 - 1; i++)
			image[i][x-1] = c;
    }
    else
    {
        for(int i = y2 - 1; i <= y1 - 1; i++)
			image[i][x-1] = c;
    }
}

void H(int x1, int x2, int y, char c)
{
    if(x2 > x1)
    {
        for(int i = x1 - 1; i <= x2 - 1; i++)
            image[y-1][i] = c;
    }
    else
    {
        for(int i = x2 - 1; i <= x1 - 1; i++)
            image[y-1][i] = c;
    }
}

void K(int x1, int y1, int x2, int y2, char c)
{
    for(int i = y1 - 1; i <= y2 - 1; i++)
        for(int j = x1 - 1; j <= x2 - 1; j++)
            image[i][j] = c;
}

void F(int x, int y, char k, char c)
{
    if(k == c)
        return;
    if(x > 0 && x <= m && y > 0 && y <= n)
    {
        image[y-1][x-1] = c;
        if(image[y-2][x-1] == k)
            F(x,y-1,k,c);
        if(image[y][x-1] == k)
            F(x,y+1,k,c);
        if(image[y-1][x-2] == k)
            F(x-1,y,k,c);
        if(image[y-1][x] == k)
            F(x+1,y,k,c);
    }
    else
        return;
}

void S(int m, int n)
{
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            cout << image[i][j];
        cout << endl;
    }
}

void read()
{
	
	char a, c, k;
    string name;
    int x, y, x1, y1, x2, y2;
    while(cin >> a)
    {
        switch(a)
        {
            case 'I':	cin >> x1 >> y1;
		                I(x1,y1);
		                break;
            case 'C':	C();
		                break;
            case 'L':	cin >> x >> y >> c;
		                L(x,y,c);
		                break;
            case 'V':
		                cin >> x >> y1 >> y2 >> c;
		                V(x,y1,y2,c);
		                break;
            case 'H':
		                cin >> x1 >> x2 >> y >> c;
		                H(x1,x2,y,c);
		                break;
            case 'K':	cin >> x1 >> y1 >> x2 >> y2 >> c;
		                K(x1,y1,x2,y2,c);
		                break;
            case 'F':	cin >> x >> y >> c;
		                k = image[y-1][x-1];
						F(x,y,k,c);
						break;
            case 'S':	cin >> name;
						cout << name << endl;
						S(m,n);
						break;
			case 'X': 	return;
            default:
                break;
        }
    }
}

int main()
{
	read();
	return 0;
}
